class PostInfosController < ManageController
layout "background"  
  
  def index
    @post_infos=PostInfo.find(:all)
  end
  
  def new 
    @post_info=PostInfo.new    
  end
  
  def create
    post_info=PostInfo.new(params[:post_info])
    post_info.user=User.find(session[:user_id])
    begin
    post_info.save!
    rescue ActiveRecord::RecordNotSaved
      notice("保存失败！")
    else
      notice("保存成功！")
    end
    redirect_to(:action=>:index)
  end
  
  def edit
    @post_info=PostInfo.find(params[:id])
  end
  
  def set_to_default
    user=User.find(session[:user_id])
    user.df_post_info=params[:id]
    begin
    user.save!
    rescue ActiveRecord::RecordNotSaved
      notice("设定失败！")
    else
      notice("设定成功！")
    end
    redirect_to(:action=>:index)
  end
  
  def update
    post_info=PostInfo.find(params[:id])
    begin
      post_info.update_attributes!(params[:post_info])
    rescue ActiveRecord::RecordNotSaved
      notice("保存失败！")
    else
      notice("保存成功！")
    end
    redirect_to(:action=>:index)
  end
  
  def destroy
    post_info=PostInfo.find(params[:id])
    begin
      post_info.destroy
      notice("删除成功！")
    end
    redirect_to(:action=>:index)
  end
  
end
